<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h2 id="time"></h2>

<script>

    var time_h2 =  document.getElementById("time")
    setInterval(function () {
        var current_date = new Date()
        //  获取年份
        var year = current_date.getFullYear()
        var month = current_date.getMonth() + 1
        var day = current_date.getDate()

        var hour = current_date.getHours() > 9 ? current_date.getHours():'0'+current_date.getHours()
        var minute = current_date.getMinutes()> 9 ? current_date.getMinutes():'0'+current_date.getMinutes()
        var seconds = current_date.getSeconds()> 9 ? current_date.getSeconds():'0'+current_date.getSeconds()

        var time_str = `今天是${year}年${month}月${day}日 ${hour}:${minute}:${seconds}`
        time_h2.innerText = time_str
    }, 1000)


</script>

</body>
</html>